﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using OGS.Contracts;
using OGS.DataAccess;
using OGS.Utility;
namespace OGS.Web.Models.Admin
{
    public class SaveUserModel
    {
        /// <summary>
        /// The ID
        /// </summary>
        public long ID
        {
            get;
            set;
        }

        /// <summary>
        /// First Name
        /// </summary>
        [Display(Name = "Full Name")]
        [Required(ErrorMessage = "Please enter full name.")]
        public string Name
        {
            get;
            set;
        }
        /// <summary>
        /// Email
        /// </summary>
        [Display(Name = "Email")]
        [Required(ErrorMessage = "Please enter email.")]
        public string Email
        {
            get;
            set;
        }
        /// <summary>
        /// Phone number
        /// </summary>
        [Display(Name = "Phone")]
        [Required(ErrorMessage = "Please enter phone number.")]
        public string Phone
        {
            get;
            set;
        }
        /// <summary>
        /// User name
        /// </summary>
        [Display(Name = "Username")]
        [Required(ErrorMessage = "Please enter username.")]
        public string Username
        {
            get;
            set;
        }
        /// <summary>
        /// Password
        /// </summary>
        [Display(Name = "Password")]
        [Required(ErrorMessage = "Please enter password.")]
        public string Password
        {
            get;
            set;
        }
        /// <summary>
        /// Confirm Password
        /// </summary>
        [Display(Name = "Confirm Password")]
        [Required(ErrorMessage = "Please enter confirm password.")]
        public string ConfirmPassword
        {
            get;
            set;
        }
        /// <summary>
        /// Shopname
        /// </summary>
        [Display(Name = "Shopname")]
        [Required(ErrorMessage = "Please enter shopname.")]
        public string Shopname
        {
            get;
            set;
        }
        /// <summary>
        /// Checks whether the Brand Is Active
        /// </summary>
        [Display(Name = "Is Active")]
        public bool IsActive
        {
            get;
            set;
        }
        [Display(Name = "Adress")]
        [Required(ErrorMessage = "Please enter adress.")]
        public string Address { get; set; }
        /// <summary>
        /// Landmark
        /// </summary>
        [Display(Name = "Landmark")]
        public string Landmark { get; set; }
        /// <summary>
        /// Zip
        /// </summary>
        [Display(Name = "Zip Code")]
        [Required(ErrorMessage = "Please enter zip code.")]
        public string Zip { get; set; }
        /// <summary>
        /// Role
        /// </summary>
        public List<Role> Role { get; set; }

        /// <summary>
        /// Role id
        /// </summary>
        [Display(Name = "Role")]
        public int RoleID { get; set; }
        [Display(Name = "Bank Account Number")]
        public string BankAccountNumber { get; set; }
        /// <summary>
        /// Bank name
        /// </summary>
        [Display(Name = "Bank Name")]
        public string BankName { get; set; }
        /// <summary>
        /// Account number
        /// </summary>
        [Display(Name = "Bank Name")]
        public string BankAccountName { get; set; }

        [Display(Name = "Location")]
        public string Location { get; set; }
        [Display(Name = "Latitude")]
        public string Latitude { get; set; }
        [Display(Name = "Longitude")]
        public string Longitude { get; set; }
        [Display(Name = "Area")]
        public string Area { get; set; }
        [Display(Name = "State")]
        public string State { get; set; }
        /// <summary>
        /// Blocked
        /// </summary>
        [Display(Name = "Blocked")]
        public bool IsBlocked { get; set; }
        /// <summary>
        /// Transaction success
        /// </summary>
        public bool IsSuccess { get; set; }
        /// <summary>
        /// Get user by id
        /// </summary>
        /// <param name="ID"></param>
        public void GetUserDetails(int ID)
        {
            User oUser = DAUser.Instance.GetUserDetails(ID: ID);
            this.ID = oUser.UserID;
            this.Name = oUser.Name;
            this.Email = oUser.Email;
            this.Shopname = oUser.ShopName;
            this.RoleID = oUser.Role.RoleID;
            this.Address = oUser.Address;
            this.Phone = oUser.Phone;
            this.Landmark = oUser.Landmark;
            this.Username = oUser.UserName;
            this.IsBlocked = oUser.IsBlocked;
            this.Zip = oUser.Zip;
            this.Area = oUser.Area;
            this.State = oUser.State;
            this.IsActive = oUser.IsActive;
            this.Latitude = oUser.Latitude.ToString();
            this.Longitude =  oUser.Longitude.ToString();
            this.Location = oUser.Location;
        }
        /// <summary>
        /// Save Brand
        /// </summary>
        public int SaveUser()
        {
            User oUser = new User();
            oUser.UserID = this.ID;
            oUser.Name = this.Name.Trim();
            oUser.Email = this.Email.Trim();
            oUser.Phone = this.Phone;
            oUser.UserName = this.Username;
            oUser.Password = this.Password;
            oUser.ShopName = this.Shopname.Trim();
            oUser.IsActive = this.IsActive;
            oUser.Address = this.Address;
            oUser.Landmark = this.Landmark;
            oUser.Zip = this.Zip;
            oUser.Role = new Contracts.Role() { RoleID = this.RoleID };
            oUser.IsBlocked = this.IsBlocked;
            oUser.LastModifiedBy = Helper.GetCurrentUserID();
            oUser.LastModifiedDate = DateTime.Now;
            oUser.Location = this.Location;
            oUser.Zip = this.Zip;
            oUser.Area = this.Area;
            oUser.State = this.State;
            if (!string.IsNullOrEmpty(this.Latitude))
                oUser.Latitude = Convert.ToDecimal(this.Latitude);
            else
                oUser.Latitude = 0;
            if (!string.IsNullOrEmpty(this.Longitude))
                oUser.Longitude = Convert.ToDecimal(this.Longitude);
            else
                oUser.Longitude = 0;
            int result = DAUser.Instance.SaveUser(oUser);
            this.ID = oUser.UserID;
            return result;
        }
        /// <summary>
        /// Populate all active roles
        /// </summary>
        public void PopulateRoles()
        {
            this.Role = DARoles.Instance.GetAllActiveRoles();
        }
    }
}